package com.woniu.work.controller;

import com.woniu.work.Service.ZfOrderService;
import org.flowable.task.api.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @program: ECP
 * @description:
 * @create: 2024-11-25 21:13
 **/
@RestController
@RequestMapping("/workflow")
public class ZfFlowableController {
    @Autowired
    private ZfOrderService flowableService;

    // 部署流程
    @PostMapping("/deploy")
    public String deployProcess() {
        return flowableService.deployProcessDefinition();
    }

    // 启动流程
    @PostMapping("/start")
    public String startProcess(@RequestParam("processDefinitionKey") String processDefinitionKey, @RequestBody Map<String, Object> variables) {
        return flowableService.startProcessInstance(processDefinitionKey, variables);
    }

    // 查询用户代办任务
    @GetMapping("/tasks")
    public List<Task> getTasks(@RequestParam("assignee") String assignee) {
        return flowableService.getUserTasks(assignee);
    }

    // 完成审批
    @PostMapping("/approve")
    public void approveTask(@RequestParam("taskId") String taskId, @RequestBody Map<String, Object> variables) {
        flowableService.completeTask(taskId, variables);
    }
}
